package com.hunan.yllxy.repostitory.dao.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hunan.yllxy.repostitory.entity.UserRole;
import com.hunan.yllxy.repostitory.mapper.UserRoleMapper;
import com.hunan.yllxy.repostitory.dao.UserRoleDao;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 刘华
 * @since 2025-06-16
 */
@Service
public class UserRoleDaoImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleDao {
    @Override
    public List<String> findByUserId(String userInfoId) {
        LambdaQueryWrapper<UserRole> wrapper = Wrappers.lambdaQuery(UserRole.class);
        wrapper.eq(UserRole::getUserId,userInfoId.trim());
        List<UserRole> userRoles = baseMapper.selectList(wrapper);
        if(userRoles == null || userRoles.size() == 0){
            return new ArrayList<>();
        }
        List<String> collect = userRoles.stream().map(UserRole::getRoleId).collect(Collectors.toList());
        return collect;
    }
}
